package com.ccl.iot.object;
public class IOTRegMonitoring {
	public long iDevID = 0;
	public long iFlagLow = 0;
	public long iFlagHigh = 0;
	
	public IOTRegMonitoring(long aDevID){
		iDevID = aDevID;
	}
	
	public boolean isMonitorable(){
		return iDevID != 0 && (iFlagLow != 0 || iFlagHigh != 0);
	}
	
	public void reset(){
		iFlagLow = 0;
		iFlagHigh = 0;
	}
	
	public int compare(IOTRegMonitoring aMonitoring){
		if (aMonitoring != null){
			if (((aMonitoring.iFlagLow & iFlagLow) != aMonitoring.iFlagLow) || ((aMonitoring.iFlagHigh & iFlagHigh) != aMonitoring.iFlagHigh)){
				return 1;
			}
		}
		
		return 0;
	}
	
	public boolean join(IOTRegMonitoring aMonitoring){
		if (aMonitoring != null){
			long tLowOld = iFlagLow;
			long tHighOld = iFlagHigh;
			
			iFlagLow |= aMonitoring.iFlagLow;
			iFlagHigh |= aMonitoring.iFlagHigh;
			
			return (iFlagLow != tLowOld) || (iFlagHigh != tHighOld);
		}
		
		return false;
	}
	
	public boolean separate(IOTRegMonitoring aMonitoring){
		if (aMonitoring != null){
			long tLowOld = iFlagLow;
			long tHighOld = iFlagHigh;
			
			iFlagLow &= (~aMonitoring.iFlagLow);
			iFlagHigh &= (~aMonitoring.iFlagHigh);
			
			return (iFlagLow != tLowOld) || (iFlagHigh != tHighOld);
		}
		
		return false;
	}

	@Override
	public String toString() {
		return iDevID + ":" + Long.toHexString(iFlagHigh) + Long.toHexString(iFlagLow);
	}
}
